/**
 * Copyright &copy; 2017-2018 <a href="http://www.webcsn.com">webcsn</a> All rights reserved.
 *
 * @author hermit
 * @date 2018-04-17 10:54:58
 */
package com.wxmp.wxcms.ctrl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wxmp.core.common.BaseCtrl;
import com.wxmp.core.util.AjaxResult;
import com.wxmp.wxcms.domain.RegisterUser;
import com.wxmp.wxcms.domain.RegisterUserType;
import com.wxmp.wxcms.service.RegisterUserService;
import com.wxmp.wxcms.service.RegisterUserTypeService;

/**
 *
 * @author hermit
 * @version 2.0
 * @date 2018-04-17 10:54:58
 */
@Controller
@RequestMapping("/registerUserType")
public class RegisterUserTypeCtrl extends BaseCtrl {

	@Autowired
	private RegisterUserTypeService entityService;
	
	@Autowired
	private RegisterUserService registerUserService;

	
	@RequestMapping(value = "/findAll")
	@ResponseBody
	public List<RegisterUserType> findAll() {
		return entityService.findAll();
	}
	
	
	/**
	 * 根据用户类型分页查询
	 * @param searchEntity
	 * @return
	 */
	@RequestMapping(value = "/listByType",method=RequestMethod.POST)
	@ResponseBody
	public AjaxResult listByType(RegisterUserType  searchEntity) {
		List<RegisterUser> list = registerUserService.getRegUserByTypeByPage(searchEntity);
		if (CollectionUtils.isEmpty(list)) {
			return AjaxResult.success();
		}
		return getResult(searchEntity,list);
	}
	
	
	
	/**
	 * 根据Id查询用户标签
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getById")
	@ResponseBody
	public AjaxResult getById(Integer id){
		return AjaxResult.success(entityService.getById(id));
	}

	/**
	 * 分页查询
	 * @param searchEntity
	 * @return
	 */
	@RequestMapping(value = "/listForPage")
	@ResponseBody
	public AjaxResult listForPage(RegisterUserType searchEntity) {
		List<RegisterUserType> list = entityService.getRegisterUserListByPage(searchEntity);
		if (CollectionUtils.isEmpty(list)) {
			return AjaxResult.success();
		}
		return getResult(searchEntity,list);
	}
	

	/**
	 * 修改/添加
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public AjaxResult update(RegisterUserType entity){
		if (entity.getId() != null) {
			entityService.update(entity);
			//更新成功
			return AjaxResult.updateSuccess();
		} else {
				entityService.add(entity);
				return AjaxResult.saveSuccess();
			}
	}

	/**
	 * 删除
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "/deleteById")
	@ResponseBody
	public AjaxResult deleteById(RegisterUserType entity) {
		entityService.delete(entity);
		return AjaxResult.deleteSuccess();
	}
	
	/**
	 * 批量删除
	 * @param String[] ids
	 * @return
	 */
	@RequestMapping(value = "/deleteBatchIds")
	@ResponseBody
	public AjaxResult deleteBatchIds(String [] ids) {
		entityService.deleteBatchIds(ids);
		return AjaxResult.deleteSuccess();
	}
}